package crivia.ecp.carry.html.form;

import crivia.ecp.carry.html.DO;

public class SelectOption extends DO {

	public SelectOption() {
		super();
	}

	public SelectOption(String value) {
		super();
		this.value = value;
		this.text = value;
	}

	public SelectOption(String value, String text) {
		super();
		this.value = value;
		this.text = text;
	}

	public SelectOption(String value, String text, boolean selected) {
		super();
		this.value = value;
		this.text = text;
		this.selected = selected;
	}

	@Override
	protected String innerHTML() {
		return text;
	}

	@Override
	protected String name() {
		return "option";
	}
	
	@Override
	public String toString() {
		addAttr("value", value);
		if (isSelected()){
			addAttr("selected", "selected");
		} else {
			getAttrs().remove("selected");
		}
		return super.toString();
	}
	
	protected String value = "";
	public String getValue() {
		return value;
	}
	public SelectOption setValue(String value) {
		this.value = value;
		return this;
	}
	
	protected String text = "";
	public String getText() {
		return text;
	}
	public SelectOption setText(String text) {
		this.text = text;
		return this;
	}
	
	protected boolean selected = false;
	public boolean isSelected() {
		return selected;
	}
	public SelectOption setSelected(boolean selected) {
		this.selected = selected;
		return this;
	}

}
